#define _CRT_SECURE_NO_WARNINGS 1
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


struct ListNode* mergeInBetween(struct ListNode* list1, int a, int b, struct ListNode* list2) {
    struct ListNode* head1 = list1;
    for (int i = 0; i < a - 1; i++) {
        head1 = head1->next;
    }
    struct ListNode* temp = head1;
    for (int i = a; i <= b + 1; i++) {
        temp = temp->next;
    }
    struct ListNode* tail2 = list2;
    while (tail2->next != NULL) {
        tail2 = tail2->next;
    }
    head1->next = list2;
    tail2->next = temp;
    return list1;
}